package com.yf.course.modules.course.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yf.ability.log.annon.LogInject;
import com.yf.ability.log.enums.LogType;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.api.api.dto.BaseIdsReqDTO;
import com.yf.base.api.api.dto.PagingReqDTO;
import com.yf.course.modules.course.dto.request.CoursePersonReqDTO;
import com.yf.course.modules.course.service.CoursePersonService;
import com.yf.system.modules.user.dto.SysUserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* <p>
* 课程人员控制器
* </p>
*
* @author 聪明笨狗
* @since 2020-12-17 11:28
*/
@Api(tags={"课程人员"})
@RestController
@RequestMapping("/api/course/person")
public class CoursePersonController extends BaseController {

    @Autowired
    private CoursePersonService baseService;


    /**
    * 添加课程人员
    * @param reqDTO
    * @return
    */
    @LogInject(title="添加课程人员", logType = LogType.COURSE)
    @RequiresPermissions(value = {"course:add", "course:update"}, logical = Logical.OR)
    @ApiOperation(value = "添加课程人员")
    @PostMapping("/join")
    public ApiRest<List<String>> join(@RequestBody BaseIdsReqDTO reqDTO) {
        List<String> list = baseService.join(reqDTO);
        return super.success(list);
    }

    /**
    * 移除课程人员
    * @param reqDTO
    * @return
    */
    @LogInject(title="移除课程人员", logType = LogType.COURSE)
    @RequiresPermissions(value = {"course:add", "course:update"}, logical = Logical.OR)
    @ApiOperation(value = "移除课程人员")
    @PostMapping("/remove")
    public ApiRest remove(@RequestBody BaseIdsReqDTO reqDTO) {
        //根据ID删除
        baseService.remove(reqDTO);
        return super.success();
    }

    /**
    * 课程人员分页
    * @param reqDTO
    * @return
    */
    @RequiresPermissions(value = {"course:add", "course:update"}, logical = Logical.OR)
    @ApiOperation(value = "课程人员分页")
    @PostMapping("/paging")
    public ApiRest<IPage<SysUserDTO>> paging(@RequestBody PagingReqDTO<CoursePersonReqDTO> reqDTO) {

        //分页查询并转换
        IPage<SysUserDTO> page = baseService.paging(reqDTO);
        return super.success(page);
    }

}
